#pragma once

#include <string>
#include "../util.hpp"

namespace pharmacy_server
{
    struct Medicine
    {
        using tuple_of_medicine = std::tuple<int, std::string, std::string, std::string, float, int, int, int>;

        Medicine() = default;

        Medicine(int id, const std::string& name, const std::string& category, const std::string& supplier, float price, int stock, int threshold, int validity)
            : id(id)
            , name(name)
            , category(category)
            , supplier(supplier)
            , price(price)
            , stock(stock)
            , threshold(threshold)
            , validity(validity)
        {
        }

        Medicine(const tuple_of_medicine& tuple)
        {
            from_tuple(tuple);
        }

        int id;
        std::string name;
        std::string category;
        std::string supplier;
        float price;
        int stock;
        int threshold;
        int validity;

        Json::Value to_json() const
        {
            Json::Value root;
            root["id"] = id;
            root["name"] = name;
            root["category"] = category;
            root["supplier"] = supplier;
            root["price"] = price;
            root["stock"] = stock;
            root["threshold"] = threshold;
            root["validity"] = validity;
            return root;
        }

        void from_json(const Json::Value& root)
        {
            id = root["id"].asInt();
            name = root["name"].asString();
            category = root["category"].asString();
            supplier = root["supplier"].asString();
            price = root["price"].asFloat();
            stock = root["stock"].asInt();
            threshold = root["threshold"].asInt();
            validity = root["validity"].asInt();
        }

        tuple_of_medicine to_tuple() const
        {
            return std::make_tuple(id, name, category, supplier, price, stock, threshold, validity);
        }

        void from_tuple(const tuple_of_medicine& tuple)
        {
            id = std::get<0>(tuple);
            name = std::get<1>(tuple);
            category = std::get<2>(tuple);
            supplier = std::get<3>(tuple);
            price = std::get<4>(tuple);
            stock = std::get<5>(tuple);
            threshold = std::get<6>(tuple);
            validity = std::get<7>(tuple);
        }

        static Medicine from_tuple_quickly(const tuple_of_medicine& tuple)
        {
            return Medicine(std::get<0>(tuple), std::get<1>(tuple), std::get<2>(tuple), std::get<3>(tuple),
                std::get<4>(tuple), std::get<5>(tuple), std::get<6>(tuple), std::get<7>(tuple));
        }
    };
}